baubs git
Commit 11b710eb1708f72bc9c4354886b9fd2da461334d
Parents : b09f97a
Author : Jan-Henrik Bruhn <hi@jhbruhn.de>
Date : 2025-12-14T12:19:21+01:00
feature: Reorganize code into formats folder structure
Moved embroidery format-related code from utils to new formats folder:
Structure:
- src/formats/pen/ - PEN format encoding and parsing
- encoder.ts (was utils/penEncoder.ts)
- encoder.test.ts (was utils/penEncoder.test.ts)
- parser.ts (was utils/penParser.ts)
- PEN constants moved inline to encoder.ts
- src/formats/import/ - Pattern import/conversion (currently PES)
- worker.ts (was workers/patternConverter.worker.ts)
- client.ts (was utils/patternConverterClient.ts)
- pesImporter.ts (was utils/pystitchConverter.ts)
- pyodideLoader.ts (was utils/pyodideLoader.ts)
- constants.ts (PyStitch/pyembroidery constants)
Benefits:
- Better separation of concerns
- PEN encoder is co-located with PEN parser
- Import logic is in one place and extensible for other formats
- Removed utils/embroideryConstants.ts - split into appropriate locations
- Updated all 18 import references across the codebase
All tests passing, build successful.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Changes
28 files changed, 2008 insertions(+), 2016 deletions(-)
Diff
diff --git a/src/components/FileUpload.tsx b/src/components/FileUpload.tsx
index 98db67c..3ed4a91 100644
--- a/src/components/FileUpload.tsx
+++ b/src/components/FileUpload.tsx
@@ -3,7 +3,7 @@ import { useShallow } from 'zustand/react/shallow';
import { useMachineStore } from '../stores/useMachineStore';
import { usePatternStore } from '../stores/usePatternStore';
import { useUIStore } from '../stores/useUIStore';
-import { convertPesToPen, type PesPatternData } from '../utils/pystitchConverter';
+import { convertPesToPen, type PesPatternData } from '../formats/import/pesImporter';
import { canUploadPattern, getMachineStateCategory } from '../utils/machineStateHelpers';
import { PatternInfoSkeleton } from './SkeletonLoader';
import { ArrowUpTrayIcon, CheckCircleIcon, DocumentTextIcon, FolderOpenIcon } from '@heroicons/react/24/solid';
diff --git a/src/components/KonvaComponents.tsx b/src/components/KonvaComponents.tsx
index 5c0e4ad..d9bce9d 100644
--- a/src/components/KonvaComponents.tsx
+++ b/src/components/KonvaComponents.tsx
@@ -1,9 +1,9 @@
import { memo, useMemo } from 'react';
import { Group, Line, Rect, Text, Circle } from 'react-konva';
-import type { PesPatternData } from '../utils/pystitchConverter';
-import { getThreadColor } from '../utils/pystitchConverter';
+import type { PesPatternData } from '../formats/import/pesImporter';
+import { getThreadColor } from '../formats/import/pesImporter';
import type { MachineInfo } from '../types/machine';
-import { MOVE } from '../utils/embroideryConstants';
+import { MOVE } from '../formats/import/constants';
interface GridProps {
gridSize: number;
diff --git a/src/components/PatternCanvas.tsx b/src/components/PatternCanvas.tsx
index c7cdbdb..208a6fd 100644
--- a/src/components/PatternCanvas.tsx
+++ b/src/components/PatternCanvas.tsx
@@ -5,7 +5,7 @@ import { usePatternStore } from '../stores/usePatternStore';
import { Stage, Layer, Group } from 'react-konva';
import Konva from 'konva';
import { PlusIcon, MinusIcon, ArrowPathIcon, LockClosedIcon, PhotoIcon, ArrowsPointingInIcon } from '@heroicons/react/24/solid';
-import type { PesPatternData } from '../utils/pystitchConverter';
+import type { PesPatternData } from '../formats/import/pesImporter';
import { calculateInitialScale } from '../utils/konvaRenderers';
import { Grid, Origin, Hoop, Stitches, PatternBounds, CurrentPosition } from './KonvaComponents';
diff --git a/src/utils/patternConverterClient.ts b/src/formats/import/client.ts
similarity index 96%
rename from src/utils/patternConverterClient.ts
rename to src/formats/import/client.ts
index 2ac46ec..785f394 100644
--- a/src/utils/patternConverterClient.ts
+++ b/src/formats/import/client.ts
@@ -1,7 +1,7 @@
-import type { WorkerMessage, WorkerResponse } from '../workers/patternConverter.worker';
-import PatternConverterWorker from '../workers/patternConverter.worker?worker';
-import { parsePenData } from './penParser';
-import type { PenData } from '../types/machine';
+import type { WorkerMessage, WorkerResponse } from './worker';
+import PatternConverterWorker from './worker?worker';
+import { parsePenData } from '../pen/parser';
+import type { PenData } from '../../types/machine';
export type PyodideState = 'not_loaded' | 'loading' | 'ready' | 'error';
diff --git a/src/utils/embroideryConstants.ts b/src/formats/import/constants.ts
similarity index 71%
rename from src/utils/embroideryConstants.ts
rename to src/formats/import/constants.ts
index 4f1f006..01e13ba 100644
--- a/src/utils/embroideryConstants.ts
+++ b/src/formats/import/constants.ts
@@ -15,9 +15,3 @@ export const TRIM = 0x20; // Trim thread command
export const COLOR_CHANGE = 0x40; // Color change command
export const STOP = 0x80; // Stop command
export const END = 0x100; // End of pattern
-
-// PEN format flags for Brother machines
-export const PEN_FEED_DATA = 0x01; // Bit 0: Jump stitch (move without stitching)
-export const PEN_CUT_DATA = 0x02; // Bit 1: Trim/cut thread command
-export const PEN_COLOR_END = 0x03; // Last stitch before color change
-export const PEN_DATA_END = 0x05; // Last stitch of entire pattern
diff --git a/src/utils/pystitchConverter.ts b/src/formats/import/pesImporter.ts
similarity index 91%
rename from src/utils/pystitchConverter.ts
rename to src/formats/import/pesImporter.ts
index fc46668..ae1b6b3 100644
--- a/src/utils/pystitchConverter.ts
+++ b/src/formats/import/pesImporter.ts
@@ -1,4 +1,4 @@
-import { patternConverterClient, type PesPatternData } from "./patternConverterClient";
+import { patternConverterClient, type PesPatternData } from "./client";
// Re-export the type for backwards compatibility
export type { PesPatternData };
diff --git a/src/utils/pyodideLoader.ts b/src/formats/import/pyodideLoader.ts
similarity index 100%
rename from src/utils/pyodideLoader.ts
rename to src/formats/import/pyodideLoader.ts
diff --git a/src/workers/patternConverter.worker.ts b/src/formats/import/worker.ts
similarity index 99%
rename from src/workers/patternConverter.worker.ts
rename to src/formats/import/worker.ts
index 2e6287d..6b0cc42 100644
--- a/src/workers/patternConverter.worker.ts
+++ b/src/formats/import/worker.ts
@@ -4,8 +4,8 @@ import {
MOVE,
TRIM,
END,
-} from '../utils/embroideryConstants';
-import { encodeStitchesToPen } from '../utils/penEncoder';
+} from './constants';
+import { encodeStitchesToPen } from '../pen/encoder';
// Message types from main thread
export type WorkerMessage =
diff --git a/src/utils/penEncoder.test.ts b/src/formats/pen/encoder.test.ts
similarity index 99%
rename from src/utils/penEncoder.test.ts
rename to src/formats/pen/encoder.test.ts
index f6945c5..e77f930 100644
--- a/src/utils/penEncoder.test.ts
+++ b/src/formats/pen/encoder.test.ts
@@ -4,8 +4,8 @@ import {
calculateLockDirection,
generateLockStitches,
encodeStitchesToPen,
-} from './penEncoder';
-import { STITCH, MOVE, TRIM, END } from './embroideryConstants';
+} from './encoder';
+import { STITCH, MOVE, TRIM, END } from '../import/constants';
// PEN format flag constants for testing
const PEN_FEED_DATA = 0x01;
diff --git a/src/utils/penEncoder.ts b/src/formats/pen/encoder.ts
similarity index 97%
rename from src/utils/penEncoder.ts
rename to src/formats/pen/encoder.ts
index eb81e3a..c2e962a 100644
--- a/src/utils/penEncoder.ts
+++ b/src/formats/pen/encoder.ts
@@ -5,15 +5,13 @@
* The PEN format uses absolute coordinates shifted left by 3 bits, with flags in the low 3 bits.
*/
-import {
- MOVE,
- TRIM,
- END,
- PEN_FEED_DATA,
- PEN_CUT_DATA,
- PEN_COLOR_END,
- PEN_DATA_END,
-} from './embroideryConstants';
+import { MOVE, TRIM, END } from '../import/constants';
+
+// PEN format flags for Brother machines
+const PEN_FEED_DATA = 0x01; // Bit 0: Jump stitch (move without stitching)
+const PEN_CUT_DATA = 0x02; // Bit 1: Trim/cut thread command
+const PEN_COLOR_END = 0x03; // Last stitch before color change
+const PEN_DATA_END = 0x05; // Last stitch of entire pattern
// Constants from PesxToPen.cs
const FEED_LENGTH = 50; // Long jump threshold requiring lock stitches and cut
diff --git a/src/utils/penParser.ts b/src/formats/pen/parser.ts
similarity index 94%
rename from src/utils/penParser.ts
rename to src/formats/pen/parser.ts
index edee9b6..80e68e7 100644
--- a/src/utils/penParser.ts
+++ b/src/formats/pen/parser.ts
@@ -1,4 +1,4 @@
-import type { PenData, PenStitch, PenColorBlock } from '../types/machine';
+import type { PenData, PenStitch, PenColorBlock } from '../../types/machine';
// PEN format flags
const PEN_FEED_DATA = 0x01; // Y-coordinate low byte, bit 0
diff --git a/src/hooks/useBrotherMachine.ts b/src/hooks/useBrotherMachine.ts
index e775f31..e0a0648 100644
--- a/src/hooks/useBrotherMachine.ts
+++ b/src/hooks/useBrotherMachine.ts
@@ -11,7 +11,7 @@ import {
} from "../services/PatternCacheService";
import type { IStorageService } from "../platform/interfaces/IStorageService";
import { createStorageService } from "../platform";
-import type { PesPatternData } from "../utils/pystitchConverter";
+import type { PesPatternData } from "../formats/import/pesImporter";
import { SewingMachineError } from "../utils/errorCodeHelpers";
export function useBrotherMachine() {
diff --git a/src/platform/browser/BrowserStorageService.ts b/src/platform/browser/BrowserStorageService.ts
index c786bc8..d79e539 100644
--- a/src/platform/browser/BrowserStorageService.ts
+++ b/src/platform/browser/BrowserStorageService.ts
@@ -1,6 +1,6 @@
import { PatternCacheService } from '../../services/PatternCacheService';
import type { IStorageService, ICachedPattern } from '../interfaces/IStorageService';
-import type { PesPatternData } from '../../utils/pystitchConverter';
+import type { PesPatternData } from '../../formats/import/pesImporter';
/**
* Browser implementation of storage service using localStorage
diff --git a/src/platform/electron/ElectronStorageService.ts b/src/platform/electron/ElectronStorageService.ts
index 5ccf44c..629c4a8 100644
--- a/src/platform/electron/ElectronStorageService.ts
+++ b/src/platform/electron/ElectronStorageService.ts
@@ -1,5 +1,5 @@
import type { IStorageService, ICachedPattern } from '../interfaces/IStorageService';
-import type { PesPatternData } from '../../utils/pystitchConverter';
+import type { PesPatternData } from '../../formats/import/pesImporter';
/**
* Electron implementation of storage service using electron-store via IPC
diff --git a/src/platform/interfaces/IStorageService.ts b/src/platform/interfaces/IStorageService.ts
index 9847221..75c7aa6 100644
--- a/src/platform/interfaces/IStorageService.ts
+++ b/src/platform/interfaces/IStorageService.ts
@@ -1,4 +1,4 @@
-import type { PesPatternData } from '../../utils/pystitchConverter';
+import type { PesPatternData } from '../../formats/import/pesImporter';
export interface ICachedPattern {
uuid: string;
diff --git a/src/services/PatternCacheService.ts b/src/services/PatternCacheService.ts
index 456c58b..3f5d64d 100644
--- a/src/services/PatternCacheService.ts
+++ b/src/services/PatternCacheService.ts
@@ -1,4 +1,4 @@
-import type { PesPatternData } from '../utils/pystitchConverter';
+import type { PesPatternData } from '../formats/import/pesImporter';
interface CachedPattern {
uuid: string;
diff --git a/src/stores/useMachineStore.ts b/src/stores/useMachineStore.ts
index e58cce4..85ffd83 100644
--- a/src/stores/useMachineStore.ts
+++ b/src/stores/useMachineStore.ts
@@ -10,7 +10,7 @@ import { SewingMachineError } from '../utils/errorCodeHelpers';
import { uuidToString } from '../services/PatternCacheService';
import { createStorageService } from '../platform';
import type { IStorageService } from '../platform/interfaces/IStorageService';
-import type { PesPatternData } from '../utils/pystitchConverter';
+import type { PesPatternData } from '../formats/import/pesImporter';
interface MachineState {
// Service instances
diff --git a/src/stores/usePatternStore.ts b/src/stores/usePatternStore.ts
index 9135d5c..21ae53e 100644
--- a/src/stores/usePatternStore.ts
+++ b/src/stores/usePatternStore.ts
@@ -1,5 +1,5 @@
import { create } from 'zustand';
-import type { PesPatternData } from '../utils/pystitchConverter';
+import type { PesPatternData } from '../formats/import/pesImporter';
interface PatternState {
// Pattern data
diff --git a/src/stores/useUIStore.ts b/src/stores/useUIStore.ts
index 70690f2..42b7cb9 100644
--- a/src/stores/useUIStore.ts
+++ b/src/stores/useUIStore.ts
@@ -1,5 +1,5 @@
import { create } from 'zustand';
-import { patternConverterClient } from '../utils/patternConverterClient';
+import { patternConverterClient } from '../formats/import/client';
interface UIState {
// Pyodide state
diff --git a/src/utils/konvaRenderers.ts b/src/utils/konvaRenderers.ts
index 21ca8bc..09fd935 100644
--- a/src/utils/konvaRenderers.ts
+++ b/src/utils/konvaRenderers.ts
@@ -1,8 +1,8 @@
import Konva from 'konva';
-import type { PesPatternData } from './pystitchConverter';
-import { getThreadColor } from './pystitchConverter';
+import type { PesPatternData } from '../formats/import/pesImporter';
+import { getThreadColor } from '../formats/import/pesImporter';
import type { MachineInfo } from '../types/machine';
-import { MOVE } from './embroideryConstants';
+import { MOVE } from '../formats/import/constants';
/**
* Renders a grid with specified spacing
Served by rngit 1.4.2 - Generated in 0.26s